<?php


namespace app\controller\partner;


use app\BaseController;
use app\model\article\ArticleModel;
use app\model\article\NoticeModel;
use app\service\config\ConfigService;

class IndexController extends BaseController
{
    public function index()
    {
        return 'partner';
    }

    /**
     * 获取最新的公告
     * @return \think\response\Json
     */
    public function getNewNotice()
    {
        try {
            $notice = ArticleModel::where('type', 4)->order('id', 'desc')->limit(3)->select();
            return $this->success($notice);
        } catch (\Exception $exception) {
            return $this->error($exception);
        }
    }

    /**
     * 公告详情
     * @return \think\response\Json
     */
    public function getNewNoticeDetail()
    {
        try {
            $id = $this->request->param('id');
            $notice = ArticleModel::where('id', $id)->find();
            return $this->success($notice);
        } catch (\Exception $exception) {
            return $this->error($exception);
        }
    }

    /**
     *获取配置信息
     * @return \think\response\Json
     */
    public function getAgreement()
    {
        try {
            $key = $this->request->param('key', '', 'trim');
            $date = NoticeModel::where('title', $key)->value('content');
            return $this->success($date);
        } catch (\Exception $exception) {
            return $this->error($exception);
        }
    }

    /**
     * 获取财务电话
     * @return \think\response\Json
     */
    public function getServiceTel()
    {
        try {
            $date = ConfigService::getConfigValue('service_tel');
            return $this->success($date);
        } catch (\Exception $exception) {
            return $this->error($exception);
        }
    }

    /**
     * 公众号ID
     * @return \think\response\Json
     */
    public function getAppId()
    {
        try {
            $data = config('payment.official_app_id');
            return $this->success($data);
        } catch (\Exception $exception) {
            return $this->error($exception);
        }
    }
}